/*******************************************************************************
*                                 ZLG
*                       ----------------------------
*                       innovating embedded platform
*
* Copyright (c) 2001-present Guangzhou ZHIYUAN Electronics Co., Ltd.
* ALL rights reserved.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* The License of this software follows LGPL v2.1, See the LICENSE for more details:
* https://opensource.org/licenses/LGPL-2.1
*
* Contact information:
* web site:    http://www.zlg.cn/
*******************************************************************************/
#ifndef __HPM6E00_CSR_REGS_H
#define __HPM6E00_CSR_REGS_H

/* \brief 标准 CSR(控制和状态寄存器) 地址定义 */
#define CSR_MSTATUS        (0x300)
#define CSR_MIE            (0x304)
#define CSR_MCOUNTEREN     (0x306)
#define CSR_MSCRATCH       (0x340)
#define CSR_MEPC           (0x341)
#define CSR_MCAUSE         (0x342)
#define CSR_PMPCFG0        (0x3A0)
#define CSR_PMPCFG1        (0x3A1)
#define CSR_PMPCFG2        (0x3A2)
#define CSR_PMPCFG3        (0x3A3)
#define CSR_PMPADDR0       (0x3B0)
#define CSR_PMPADDR1       (0x3B1)
#define CSR_PMPADDR2       (0x3B2)
#define CSR_PMPADDR3       (0x3B3)
#define CSR_PMPADDR4       (0x3B4)
#define CSR_PMPADDR5       (0x3B5)
#define CSR_PMPADDR6       (0x3B6)
#define CSR_PMPADDR7       (0x3B7)
#define CSR_PMPADDR8       (0x3B8)
#define CSR_PMPADDR9       (0x3B9)
#define CSR_PMPADDR10      (0x3BA)
#define CSR_PMPADDR11      (0x3BB)
#define CSR_PMPADDR12      (0x3BC)
#define CSR_PMPADDR13      (0x3BD)
#define CSR_PMPADDR14      (0x3BE)
#define CSR_PMPADDR15      (0x3BF)
#define CSR_PMACFG0        (0xBC0)
#define CSR_PMACFG1        (0xBC1)
#define CSR_PMACFG2        (0xBC2)
#define CSR_PMACFG3        (0xBC3)
#define CSR_PMAADDR0       (0xBD0)
#define CSR_PMAADDR1       (0xBD1)
#define CSR_PMAADDR2       (0xBD2)
#define CSR_PMAADDR3       (0xBD3)
#define CSR_PMAADDR4       (0xBD4)
#define CSR_PMAADDR5       (0xBD5)
#define CSR_PMAADDR6       (0xBD6)
#define CSR_PMAADDR7       (0xBD7)
#define CSR_PMAADDR8       (0xBD8)
#define CSR_PMAADDR9       (0xBD9)
#define CSR_PMAADDR10      (0xBDA)
#define CSR_PMAADDR11      (0xBDB)
#define CSR_PMAADDR12      (0xBDC)
#define CSR_PMAADDR13      (0xBDD)
#define CSR_PMAADDR14      (0xBDE)
#define CSR_PMAADDR15      (0xBDF)
#define CSR_CYCLE          (0xC00)
#define CSR_CYCLEH         (0xC80)
#define CSR_MHARTID        (0xF14)

/* \brief 非标准 CSR(控制和状态寄存器) 地址定义 */
#define CSR_MCACHE_CTL     (0x7CA)
#define CSR_MCCTLBEGINADDR (0x7CB)
#define CSR_MCCTLCOMMAND   (0x7CC)
#define CSR_MMISC_CTL      (0x7D0)


#define CSR_MSTATUS_FS_MASK                 (0x6000U)
#define CSR_MSTATUS_FS_INIT                 (0x1 << 13)   /* 初始化状态*/
#define CSR_MSTATUS_FS_POS                  (13U)
#define CSR_MSTATUS_FS_SET(x)              (((uint32_t)(x) << CSR_MSTATUS_FS_POS) & CSR_MSTATUS_FS_MASK)
#define CSR_MSTATUS_FS_GET(x)              (((uint32_t)(x) & CSR_MSTATUS_FS_MASK) >> CSR_MSTATUS_FS_POS)

/**
 * \brief MEIE，机器模式外部中断使能位
 */
#define CSR_MIE_MEIE_MASK                    (0x800U)
#define CSR_MIE_MEIE_POS                     (11U)
#define CSR_MIE_MEIE_SET(x)                (((uint32_t)(x) << CSR_MIE_MEIE_POS) & CSR_MIE_MEIE_MASK)
#define CSR_MIE_MEIE_GET(x)                (((uint32_t)(x) & CSR_MIE_MEIE_MASK) >> CSR_MIE_MEIE_POS)

/**
 * \brief MIE，机器模式中断使能位
 */
#define CSR_MSTATUS_MIE_MASK                 (0x8U)
#define CSR_MSTATUS_MIE_POS                  (3U)
#define CSR_MSTATUS_MIE_SET(x)             (((uint32_t)(x) << CSR_MSTATUS_MIE_POS) & CSR_MSTATUS_MIE_MASK)
#define CSR_MSTATUS_MIE_GET(x)             (((uint32_t)(x) & CSR_MSTATUS_MIE_MASK) >> CSR_MSTATUS_MIE_POS)


/**
 * \brief 异常代码位
 */
#define CSR_MCAUSE_EXCEPTION_CODE_MASK       (0xFFFU)
#define CSR_MCAUSE_EXCEPTION_CODE_POS        (0U)
#define CSR_MCAUSE_EXCEPTION_CODE_SET(x)   (((uint32_t)(x) << CSR_MCAUSE_EXCEPTION_CODE_POS) & CSR_MCAUSE_EXCEPTION_CODE_MASK)
#define CSR_MCAUSE_EXCEPTION_CODE_GET(x)   (((uint32_t)(x) & CSR_MCAUSE_EXCEPTION_CODE_MASK) >> CSR_MCAUSE_EXCEPTION_CODE_POS)

#endif  /* __HPM6E00_CSR_REGS_H */
